<?php


namespace app\api\controller;


use app\common\controller\Api;

/**
 * 用户接口
 */
class UserOperate extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';


    public function _initialize()
    {
        parent::_initialize();

    }


    /**
     * 用户-分销数据统计列表
     * @ApiMethod GET
     * @ApiParams int $user_id
     */
    public function getUserBrokerageLogList(\app\common\model\UserBrokerageLogModel $UserBrokerageLogModel)
    {
        $user_id = $this->auth->id;
        $return = $UserBrokerageLogModel->getList($user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }


    /**
     * 用户-分销数据统计列表2
     * @ApiMethod GET
     * @ApiParams int $user_id
     * @ApiParams int $group_id
     */
    public function getGroupUserBrokerageLogList(\app\common\model\UserBrokerageLogModel $UserBrokerageLogModel)
    {
        $group_id = $this->request->request('group_id',1);
        $user_id = $this->auth->id;
//        $return = $UserBrokerageLogModel->getList2($user_id,$group_id);
        $return = $UserBrokerageLogModel->getList3($user_id,$group_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }


    /**
     * 用户-分销数据统计列表4
     * @ApiMethod GET
     */
    public function getGroupUserBrokerageLogList4(\app\common\model\UserBrokerageLogModel $UserBrokerageLogModel)
    {
        $user_id = $this->auth->id;
        $return = $UserBrokerageLogModel->getList4($user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }


    /**
     * 提现
     * @ApiMethod POST
     *
     * @param $withdraw_money int 提现金额
     * @param $name string 姓名
     * @param $account string 提现账号/卡号
     * @param $bank string 开户行
     * @param $memo string 用户备注
     */
    public function applyWithdraw(\app\common\model\UserWithdrawModel $UserWithdrawModel, \app\api\validate\UserWithdrawValidate $UserWithdrawValidate)
    {
        $params = $this->request->post();
        if(!$UserWithdrawValidate->check($params,[],'applyWithdraw')){
            $this->errorReturn(40001,$params,$UserWithdrawValidate->getError());
        }
        $user_id = $this->auth->id;
        $return = $UserWithdrawModel->applyWithdraw($params,$user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }

    /**
     * 提现申请记录
     * @ApiMethod GET
     *
     * @param string $mold 状态:-1=全部,0=待审核,1=审核通过,2=审核拒绝
     * @param int $page 页码
     * @param int $limit 每页数据
     */
    public function withdrawLog(\app\common\model\UserWithdrawModel $UserWithdrawModel)
    {
        $mold = $this->request->request("mold",-1);
        $page = $this->request->request("page",1);
        $limit = $this->request->request("limit",10);
        $user_id = $this->auth->id;
        $return = $UserWithdrawModel->getPageList($user_id,$mold,$page,$limit);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }


    /**
     * 个人邀请二维码
     */
    public function getUserQrCode(\app\common\model\WxCode $WxCode)
    {
        $user_id = $this->auth->id;
        $return = $WxCode->getUserQrCode($user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }


    /**
     * 个人邀请海报图
     */
    public function getUserInvitePosterImage(\app\common\model\WxCode $WxCode)
    {
        $user_id = $this->auth->id;
        $return = $WxCode->getUserInvitePosterImage($user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }


    /**
     * 绑定用户关系
     *
     * tip:
     * 前端校验,满足下面三个条件就调一次接口,邀请码用过后清除
     * 1.用户登录了
     * 2.是用户身份
     * 3.获取到了邀请码
     *
     * @ApiParams string $invite_code 用户邀请码
     */
    public function bindUserRelation(\app\common\model\UserRelationModel $UserRelationModel,\app\api\validate\UserOperateValidate $UserOperateValidate)
    {
        $params = $this->request->post();
        if(!$UserOperateValidate->check($params,[],'bindUserRelation')){
            $this->errorReturn(40001,$params,$UserOperateValidate->getError());
        }
        $user_id = $this->auth->id;
        $return = $UserRelationModel->bindUserRelation($params,$user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }



}